package com.java.exer_5;

import java.util.Arrays;

public class Player {
    private String name;
    private Poker[] pokers;

    public Player(String name) {
        super();
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Poker[] getPokers() {
        return pokers;
    }

    public void setPokers(Poker[] pokers) {
        this.pokers = pokers;
    }

    @Override
    public String toString() {
        String info = "[暗牌, ";
        for (int i = 1; i < pokers.length; i++) {
            info += pokers[i].toString();
            if (i != pokers.length - 1) {
                info += ", ";
            }
        }

        return this.name + ": \n" +
                info + "]";
    }

    public String getInfo() {

        return this.name + ": \n" +
                Arrays.toString(this.pokers);
    }

    /**
     * 获得点数
     */
    public int getPointers() {
        int pointers = 0;
        int countA = 0;
        for (Poker poker : pokers) {

            if (poker.getNum() == 1) {
                pointers += 11;
                countA++;
            } else if (poker.getNum() > 10) {
                pointers += 10;
            } else {
                pointers += poker.getNum();
            }
        }

        //
        if (pointers > 21) {
            pointers -= countA * 10;
        }

        return pointers;
    }

    /**
     * 收牌
     */
    public void getPoker(Poker poker) {
        if (this.pokers == null) {
            this.pokers = new Poker[1];
        } else {

            Poker[] newArray = new Poker[pokers.length + 1];

            for (int i = 0; i < pokers.length; i++) {
                newArray[i] = pokers[i];
            }

            pokers = newArray;
        }

        pokers[pokers.length - 1] = poker;
    }


}
